import xadmin
from xadmin import views
from xadmin.layout import Row,Fieldset

from django.contrib import admin
from django.contrib.admin.models import LogEntry

from django.urls import reverse
from django.utils.html import format_html

from .adminforms import PostAdminForm
from .models import Post,Category,Tag
from typeidea.base_admin import BaseOwnerAdmin
from typeidea.custom_site import custom_site


class BaseSetting(object):
    """xadmin的基本配置"""
    enable_themes = True  # 开启主题切换功能
    use_bootswatch = True
xadmin.site.register(views.BaseAdminView, BaseSetting)

class GlobalSettings(object):
    """xadmin的全局配置"""
    print('a')
    site_title = "融诺科技"  # 设置站点标题
    site_footer = "唐山融诺科技有限公司"  # 设置站点的页脚
    menu_style = "accordion"  # 设置菜单折叠
xadmin.site.register(views.CommAdminView, GlobalSettings)

#admin.TabularInline
class PostInline(object):# TabularInline 横向 /   StackedInline 纵向   样式不同
    #作用：在同一页面编辑关联数据  可在分类页面编辑文章
 
    fields=('title','desc')
    extra=1 #控制额外多几个
    model=Post



class CategoryAdmin(object):

    inlines=[PostInline]#作用：在同一页面编辑关联数据  可在分类页面编辑文章 对应上面的 class PostInline(admin.TabularInline):

    list_display=('name','status','is_nav','created_time','post_count')
    fields=('name','status','is_nav')

    def post_count(self,obj):
        return obj.post_set.count()
    post_count.short_description='文章数量'

xadmin.site.register(Category,CategoryAdmin)